package com.yolib.sanyi.pic;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import com.yolib.sanyi.tool.Utility;
import com.yolib.sanyi.tool.YoliBLog;



import android.graphics.Bitmap;
import android.graphics.BitmapFactory;


public class DownloadPic {


	public static void getPic(String fileID, LoadCallback callback) {

		URL img_value = null;
		try {
			YoliBLog.e("Download start");
			img_value = new URL(Utility.getIMGAPIURL() + fileID);
			YoliBLog.e("Download path: "+ img_value);
			Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
			callback.result(LoadCallback.LOAD_SUCCESS, fileID, mIcon1);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			callback.result(LoadCallback.LOAD_FAIL, fileID, null);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			callback.result(LoadCallback.LOAD_FAIL, fileID, null);
		}catch(OutOfMemoryError e){
			e.printStackTrace();
			callback.result(LoadCallback.LOAD_FAIL, fileID, null);
		}	

	}

}
